package com.cxs.shopstore.task;

import com.cxs.shopstore.config.ImgCodeConf;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Set;

/*
 * @Author:cxs
 * @Date:2021/5/21  11:12
 * @Version 1.0
 * */
@Slf4j
@Component
public class ClearRedisImgKeyTask {
    @Autowired
    private RedisTemplate<String,Object> redisTemplate;
    @Autowired
    private ImgCodeConf imgCodeConf;
    @Scheduled(fixedDelay = 1080000*10)
    public void clearRedisImgKey(){
        Set<String> keys = redisTemplate.keys(imgCodeConf.getPrifex() + "*");
        Long delete = redisTemplate.delete(keys);
        if(delete > 0){
            log.info(new Date().toString() + "; deleted key" + delete);
        }
    }
}
